package com.quartet.modules.vehicle.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.vehicle.dao.TVehicleDetailInfoDao;
import com.quartet.modules.vehicle.dto.TVehicleDetailInfoAddRequestDto;
import com.quartet.modules.vehicle.entity.TVehicleDetailInfo;
import com.quartet.modules.vehicle.service.TVehicleDetailInfoService;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 车辆详细信息表(TVehicleDetailInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 17:09:39
 */
@Service("tVehicleDetailInfoService")
public class TVehicleDetailInfoServiceImpl extends ServiceImpl<TVehicleDetailInfoDao, TVehicleDetailInfo> implements TVehicleDetailInfoService {

    /**
     * 添加车辆详细信息
     *
     * @param tVehicleDetailInfoAddRequestDto
     */
    @Override
    public void addVehicleDetailInfo(TVehicleDetailInfoAddRequestDto tVehicleDetailInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tVehicleDetailInfoAddRequestDto)) {
            TVehicleDetailInfo tVehicleDetailInfo = BeanUtil.copyProperties(tVehicleDetailInfoAddRequestDto, TVehicleDetailInfo.class);
            this.baseMapper.insert(tVehicleDetailInfo);
        }
    }

    /**
     * 功能描述: 修改车辆详细信息
     * @author huipanxing huipanxing@chinasofti.com
     * @date 2021/5/13 16:15
     * @param tVehicleDetailInfoAddRequestDto
     * @return void
     */
    @Override
    public void updateVehicleDetailInfo(TVehicleDetailInfoAddRequestDto tVehicleDetailInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tVehicleDetailInfoAddRequestDto)) {
            TVehicleDetailInfo tVehicleDetailInfo = BeanUtil.copyProperties(tVehicleDetailInfoAddRequestDto, TVehicleDetailInfo.class);
            this.baseMapper.updateById(tVehicleDetailInfo);
        }
    }

    /**
     * 根据车辆编码删除车辆详情信息
     * @param vehicleCode
     */
    @Override
    public void deleteVehicleDetailInfo(String vehicleCode) {
        this.baseMapper.delete(new QueryWrapper<TVehicleDetailInfo>().lambda().eq(TVehicleDetailInfo::getVehicleCode,vehicleCode));
    }

    /**
     * 根据车辆编码查询车辆详情信息
     * @param vehicleCode
     * @return
     */
    @Override
    public TVehicleDetailInfoAddRequestDto selectVehicleDetailInfo(String vehicleCode) {
        TVehicleDetailInfo tVehicleDetailInfo = this.baseMapper.selectOne(new QueryWrapper<TVehicleDetailInfo>().lambda().eq(TVehicleDetailInfo::getVehicleCode, vehicleCode));
        TVehicleDetailInfoAddRequestDto tVehicleDetailInfoAddRequestDto = BeanUtil.copyProperties(tVehicleDetailInfo, TVehicleDetailInfoAddRequestDto.class);
        return tVehicleDetailInfoAddRequestDto;
    }
}
